﻿<div>
    <script type="text/javascript" language="javascript"> 

        function InitialDate(paraYearID,paraMonthID,paraDayID)
        {
            
            MonDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
            var year = new Date().getFullYear();
            var month = new Date().getMonth() + 1;
            var day = new Date().getDate();
            var paraYear = document.getElementById(paraYearID);
            var paraMonth = document.getElementById(paraMonthID);
            var paraDay = document.getElementById(paraDayID);
            paraYear.options.length = 0;
            paraYear.options.add(new Option('-请选择-',-1));
            for(var i = year; i >= year - 100; i--)
            {
                paraYear.options.add(new Option(i, i));
            }
            paraYear.value = -1;
            paraMonth.options.length = 0;
            paraMonth.options.add(new Option('-请选择-',-1));
            for(var i = 1; i <= 12; i++)
            {
                paraMonth.options.add(new Option(i, i));
            }
            paraMonth.value = -1;

            var daysNumber = MonDays[month - 1];
            if (month == 2 && isLeapYear(year))
            {
                daysNumber ++;
            }
            paraDay.options.length = 0;
            FillDayOptions(daysNumber,paraDayID);
            paraDay.value = -1;
        }
        

        function isLeapYear(year)
        {
            return ((year % 4 == 0)||(year % 100 == 0) && (year % 400 == 0))
        }
        
        function FillDayOptions(dayCount,paraDayID)
        {
            var paraDay = document.getElementById(paraDayID);
            paraDay.options.length = 0;
            paraDay.options.add(new Option('-请选择-',-1));   
            for (var i = 1; i <= dayCount; i++)
            {
                paraDay.options.add(new Option(i,i));
            }
        }
        function ChangeDate(paraYearID,paraMonthID,paraDayID)
        {
            var paraYear = document.getElementById(paraYearID);
            var paraMonth = document.getElementById(paraMonthID);
            var paraDay = document.getElementById(paraDayID);
            var year = paraYear.options[paraYear.selectedIndex].value;
            var month = paraMonth.options[paraMonth.selectedIndex].value;
            MonDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
            var day = MonDays[month - 1];
            if ((month == 2) && isLeapYear(year))
            {
                day++;
            }
            paraDay.options.length = 0;
            FillDayOptions(day, paraDayID);
        }
        function GetUserBirthday()
        {
            if(document.getElementById("yearhidden").value != 1800)
            {   
                document.getElementById("year").value = document.getElementById("yearhidden").value;
                document.getElementById("month").value = document.getElementById("monthhidden").value;
                document.getElementById("day").value = document.getElementById("dayhidden").value;
             }
        }
    </script>
    <table>
        <tr>
            <td>
                <select id="year" name="year"  onchange="ChangeDate('year','month','day');"></select>
                <select id="month" name="month" onchange="ChangeDate('year','month','day');"></select>
                <select id="day" name="day"></select>
                <input type="hidden" id="yearhidden" value="{UserData.Birthday.Year}" />
                <input type="hidden" id="monthhidden" value="{UserData.Birthday.Month}" />
                <input type="hidden" id="dayhidden" value="{UserData.Birthday.Day}" />
            </td>
        </tr>
    </table>
    <script>
    InitialDate('year','month','day');
    GetUserBirthday();
    </script>



</div>